package com.wk.kxexamadminister.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wk.kxexamadminister.entity.*;
import com.wk.kxexamadminister.mapper.JudgmentMapper;
import com.wk.kxexamadminister.mapper.ManyChoiceMapper;
import com.wk.kxexamadminister.mapper.SingleMapper;
import com.wk.kxexamadminister.mapper.fillBlanksMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Collection;

import javax.jws.WebParam;
import java.util.*;

@Controller
public class ChoiceController {
    @Autowired
    private SingleMapper singleMapper;
    @Autowired
    private ManyChoiceMapper manyChoiceMapper;
    @Autowired
    private JudgmentMapper judgmentMapper;
    @Autowired
    private fillBlanksMapper fillBlanksMapper;



    @GetMapping("/seeChoice")
    public String look(Model model,Integer cId){
        List<SingleChoiceExt> singleChoices = singleMapper.findAllSingleChoice(cId);
        for (SingleChoice singleChoice : singleChoices) {
            String[] split = singleChoice.getDescription().split(",");
            List<String> list = Arrays.asList(split);
            Collections.shuffle(list);
            singleChoice.setDescription(String.join(",",list));
        }
        Collections.shuffle(singleChoices);
        model.addAttribute("singleChoices",singleChoices);

        // 多选
        List<ManyChoice> allManyChoice = manyChoiceMapper.selectList(null);
        for (ManyChoice manyChoiceExt : allManyChoice) {
            manyChoiceExt.setDescription(aVoid(manyChoiceExt.getDescription()));
        }
        Collections.shuffle(allManyChoice);
        model.addAttribute("allManyChoice",allManyChoice);


        List<Judgment> judgments = judgmentMapper.selectList(null);
        Collections.shuffle(judgments);
        model.addAttribute("judgments",judgments);

        List<fillBlanks> fillBlanks = fillBlanksMapper.selectList(null);
        Collections.shuffle(fillBlanks);
        model.addAttribute("fillBlanks",fillBlanks);

        return "15-pagePreView";
    }



    public static String aVoid(String s){
        String[] split = s.split(",");
        List<String> list = Arrays.asList(split);
        Collections.shuffle(list);
        String join = String.join(",", list);
        return join;
    }



}
